#include<unordered_map>
#include<map>
#include<string>
#include<set>
#include<vector>
#include<memory>
#include<mutex>
#include"TcpConnection.h"
using std::unordered_map;
using std::pair;
using std::string;
using std::set;
using std::vector;
using std::shared_ptr;
using std::mutex;
using std::unique_lock;
using TcpConnectionPtr=shared_ptr<TcpConnection>;
class LRU;
class WebPageQuery{
    public:
    WebPageQuery(const string &sentence,TcpConnectionPtr conn,LRU&lru);//const string &sentence
    void loadLibrary();
    bool executeQuery(vector<string> &wordList,vector<double> &);

    set<int> intersectMultipleSets(const vector<set<int>>& sets);

    double vectorMagnitude(const std::vector<double>& vec) ;
    double dotProduct(const std::vector<double>& vec1, const std::vector<double>& vec2);
    double cosineSimilarity(const std::vector<double>& vec1, const std::vector<double>& vec2);
    string removeNorR(const string&input );
    private:
    unordered_map<int,pair<int,int>> _offsetLib;
    unordered_map<string,set<pair<int,double>>> _invertIndexTable;
    unordered_map<string,int> stopMap;
    TcpConnectionPtr _conn;
    LRU& _lru;
    mutex _lock;
};
class SentenceRes{
    public:
    SentenceRes(int,double);
    bool operator<(const SentenceRes&rhs)const;
    int getIndex()const;
    void print()const;
    private:
    int _index;
    double _sim;
};